#pragma once

#include <QtCore/QMap>

#include "exports.hpp"
#include "StyleDefinition.hpp"
#include "CssClass.hpp"




namespace Engine
{
	namespace Ui
	{
		class ENGINE_UI_API Parser
		{
		public:

			typedef std::vector<Error>   Errors;

		public:

			Parser(BasicStyleDefinition* styleDefinition);

			/**
			 * Parses the given code into the given css document.
			 * All errors are stored and may be retrived through
			 * errors().
			 */
			bool parse(QString code);

			/**
			 * Get a list of all errors that have been encountered during
			 * parsing & expanding.
			 */
			const Errors& errors() const;

		private:

			/**
			 * Get a QString from a std::string.
			 */
			static boost::any string(const std::string& str);

			/**
			 * Get the glyph with the given name.
			 * This function is used by the css parser.
			 */
			boost::any glyph(const std::string& name);

			/**
			 * Get a color for the given name.
			 */
			static boost::any color(const std::string& _data);

			/**
			 * Extract a size from the given data.
			 */
			static boost::any size(const std::string& data);

			/**
			 * Extract a resizing type from the given data.
			 */
			static boost::any resizing(const std::string& data);



			/**
			 * Create a WidgetStyle from a css class.
			 */
			WidgetStyle::ptr createStyle(CssClass& c);

			/**
			 * Create a WidgetStyleIdentifier from a css class.
			 */
			WidgetStyleIdentifier createIdentifier(const CssClass& c);

		private:

			BasicStyleDefinition*   m_styleDefinition;
			Errors                  m_errors;
		};
		///////////////////////////////////////////////////////////////////////////////////////////
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////////////////////////////////////
